package com.example.tests;

import com.example.framework.GroupData;
import com.example.utils.SortedListOf;
import org.testng.annotations.Test;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

public class GroupModificationTest extends TestManager {

    @Test(dataProvider = "validGroup")
    public void shouldChangeAllGroupFields(GroupData group){
        // save old state
        SortedListOf<GroupData> oldGroupList = new SortedListOf<GroupData>(manager.getHibernateHelper().listGroups());

        // actions
        int index = rnd.nextInt(oldGroupList.size() - 1);
        manager.getGroupHelper().modifyGroupByIndex(index, group);

        // save new state
        SortedListOf<GroupData> newGroupList = manager.getGroupHelper().getGroups();

        // compare states
        assertThat(newGroupList, equalTo(oldGroupList.without(index).withAdded(group)));
    }
}
